<?php
declare (strict_types=1);

namespace app\command;

use app\common\enum\MainEnum;
use app\common\service\Email;
use app\common\service\RabbitMQ;
use PhpAmqpLib\Message\AMQPMessage;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

class Test extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('test')->setDescription('test');
    }

    protected function execute(Input $input, Output $output)
    {
        #RabbitMQ生产者
        $mqModel = new RabbitMQ();
        $mqModel->setExchange(MainEnum::RabbitMQ['exchange']['消息'])->setRoutingKey(
            MainEnum::RabbitMQ['routingKey']['消息|用户注册成功']
        )->setQueue(MainEnum::RabbitMQ['queue']['消息|用户注册成功'])->setConfirmSelectType(
            3,
            [
                static function (AMQPMessage $message) {
                    echo 'Message acked with content ' . $message->body . PHP_EOL;
                },
                static function (AMQPMessage $message) {
                    echo 'Message nacked with content ' . $message->body . PHP_EOL;
                },
                static function ($replyCode, $replyText, $exchange, $routingKey, AMQPMessage $message) {
                    echo 'Message returned with content ' . $message->body . PHP_EOL;
                },
            ]
        )->preparePublisher();
        $temp = [];
        for ($i = 1; $i < 200000000; $i++) {
            $temp[] = [
                'nihao',
            ];
            if (is_int($i / 1000)) {
                $mqModel->publisher($temp);
                $temp = [];
                sleep(1);
            }
        }
    }
}
